gtk4.git
4 years agox11: ensure WM class is not null even if display is initialized early
Vincent Bernat [Sat, 31 Jul 2021 10:29:47 +0000 (12:29 +0200)]
x11: ensure WM class is not null even if display is initialized early

With gtkmm, when using `Application()`, the display is initialized
before we know the application name and therefore, the program class
associated to the display is NULL.

Instead of providing a default value, we set it equal to program name
when NULL. Moreover, we give up on capitalizing the class name to keep
the code super simple. Also, not using a capitalized name is
consistent with `gdk_x11_display_open()`. If someone has a good reason
to use a capitalized name, here is how to do it.

```c
  class_hint = XAllocClassHint ();
  class_hint->res_name = (char *) g_get_prgname ();
  if (display_x11->program_class)
    {
      class_hint->res_class = (char *) g_strdup (display_x11->program_class);
    }
  else if (class_hint->res_name && class_hint->res_name[0])
    {
      class_hint->res_class = (char *) g_strdup (class_hint->res_name);
      class_hint->res_class[0] = g_ascii_toupper (class_hint->res_class[0]);
    }
  XSetClassHint (xdisplay, impl->xid, class_hint);
  g_free (class_hint->res_class);
  XFree (class_hint);
```

Fix eff53c023a26 ("x11: set a default value for program_class")

4 years agoMerge branch 'glyph-cache-mystery' into 'master'
Matthias Clasen [Sat, 31 Jul 2021 00:38:41 +0000 (00:38 +0000)]
Merge branch 'glyph-cache-mystery' into 'master'

ngl: Bypass pango for glyph cache rendering

See merge request GNOME/gtk!3807

4 years agongl: Bypass pango for glyph cache rendering
Matthias Clasen [Fri, 30 Jul 2021 17:51:02 +0000 (13:51 -0400)]
ngl: Bypass pango for glyph cache rendering

We can just use cairo directly here,
and cut out some layers of pango in the middle.

4 years agoMerge branch 'check-activate' into 'master'
Matthias Clasen [Fri, 30 Jul 2021 23:39:17 +0000 (23:39 +0000)]
Merge branch 'check-activate' into 'master'

checkbutton: Some fixes when used with GActions

See merge request GNOME/gtk!3805

4 years agoMerge branch 'fix/wm_class' into 'master'
Matthias Clasen [Fri, 30 Jul 2021 23:25:08 +0000 (23:25 +0000)]
Merge branch 'fix/wm_class' into 'master'

x11: set a default value for program_class

Closes #4138

See merge request GNOME/gtk!3806

4 years agoMerge branch 'wip/otte/for-master' into 'master'
Matthias Clasen [Fri, 30 Jul 2021 22:43:29 +0000 (22:43 +0000)]
Merge branch 'wip/otte/for-master' into 'master'

widget-factory: Expand the video to cover the whole frame

See merge request GNOME/gtk!3804

4 years agox11: set a default value for program_class
Vincent Bernat [Fri, 30 Jul 2021 21:21:19 +0000 (23:21 +0200)]
x11: set a default value for program_class

This was also the behaviour with GTK 3. We use the capitalized program
name.

Fixes #4138

Signed-off-by: Vincent Bernat <vincent@bernat.ch>
4 years agowidget-factory: Propagate natural size for text styles
Benjamin Otte [Fri, 30 Jul 2021 18:54:58 +0000 (20:54 +0200)]
widget-factory: Propagate natural size for text styles

This avoids them requiring scrolling.

4 years agowidget-factory: Make frames cooler
Benjamin Otte [Fri, 30 Jul 2021 18:41:30 +0000 (20:41 +0200)]
widget-factory: Make frames cooler

Instead of havoing a label for the video frame that clashes with the
background of the video, add a frame around the text styles box and add
a label for them. As a side benefit, it also makes it more obvious that
it is scrollable.

Note: Most of this patch is just reindenting.

4 years agowidget-factory: Expand the video to cover the whole frame
Benjamin Otte [Fri, 30 Jul 2021 18:37:34 +0000 (20:37 +0200)]
widget-factory: Expand the video to cover the whole frame

1. This looks way cooler.

2. Since the frame is rounded, it adds a very visible test for our
   clipping of rounded rectangles.

4 years agocheckbutton: Activate when moving focus
Florian Müllner [Fri, 30 Jul 2021 18:18:36 +0000 (20:18 +0200)]
checkbutton: Activate when moving focus

Currently we update the :active property on both the previous and
new focus button. That "visually activate" the button and will
emit ::toggled, but if the button is associated with an action,
the action state won't change.

Fix that by activating the new focus instead of explicitly fiddling
with the :active property.

4 years agocheckbutton: Delegate ::activate to the helper if appropriate
Florian Müllner [Fri, 30 Jul 2021 05:40:48 +0000 (07:40 +0200)]
checkbutton: Delegate ::activate to the helper if appropriate

If the button is associated with an action, the action is currently
only activated when the button is clicked, not when it is activated.

4 years agoMerge branch 'wip/chergert/fix-4134' into 'master'
Matthias Clasen [Fri, 30 Jul 2021 13:41:30 +0000 (13:41 +0000)]
Merge branch 'wip/chergert/fix-4134' into 'master'

textview: fix yoffset position when top_margin is set

Closes #4134

See merge request GNOME/gtk!3801

4 years agotextview: fix yoffset position when top_margin is set
Christian Hergert [Thu, 29 Jul 2021 23:45:04 +0000 (16:45 -0700)]
textview: fix yoffset position when top_margin is set

This doesn't need to be included in the calculation or it will cause the
yoffset to continually shift while the window is resized.

Fixes #4134

4 years agoMerge branch 'source-static-name' into 'master'
Matthias Clasen [Thu, 29 Jul 2021 11:59:02 +0000 (11:59 +0000)]
Merge branch 'source-static-name' into 'master'

Avoid copying static debug strings

See merge request GNOME/gtk!3789

4 years agoci: Collect tools test output
Matthias Clasen [Wed, 28 Jul 2021 17:41:33 +0000 (13:41 -0400)]
ci: Collect tools test output

This should help understanding why some of them fail.

4 years agotestsuite: Set TEST_RESULT_DIR for tools tests
Matthias Clasen [Wed, 28 Jul 2021 17:21:03 +0000 (13:21 -0400)]
testsuite: Set TEST_RESULT_DIR for tools tests

4 years agoAvoid copying static debug strings
Matthias Clasen [Mon, 26 Jul 2021 21:03:15 +0000 (17:03 -0400)]
Avoid copying static debug strings

The g_source_set_name calls were showing up as a
major source of strdups in our profiles. Avoid that
by using new GLib api when available.

4 years agoMerge branch 'compose-parse-msvc' into 'master'
Matthias Clasen [Wed, 28 Jul 2021 10:38:25 +0000 (10:38 +0000)]
Merge branch 'compose-parse-msvc' into 'master'

compose-parse.c: Include stdlib.h (fix build on Visual Studio)

See merge request GNOME/gtk!3794

4 years agoUpdate Friulian translation
Fabio Tomat [Wed, 28 Jul 2021 09:11:12 +0000 (09:11 +0000)]
Update Friulian translation

(cherry picked from commit 16aa8dbad74ac7dd29fa2e807e57c34f00eef3a7)

4 years agocompose-parse.c: Include stdlib.h
Chun-wei Fan [Wed, 28 Jul 2021 07:10:37 +0000 (15:10 +0800)]
compose-parse.c: Include stdlib.h

That is needed for exit(), and it may not have been included by the
other headers.

4 years agoMerge branch 'gi-fix' into 'master'
Emmanuele Bassi [Tue, 27 Jul 2021 17:38:28 +0000 (17:38 +0000)]
Merge branch 'gi-fix' into 'master'

gdk: add missing Since annotation

See merge request GNOME/gtk!3790

4 years agogdk: add missing Since annotation
Marc-André Lureau [Tue, 27 Jul 2021 17:01:31 +0000 (21:01 +0400)]
gdk: add missing Since annotation

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
4 years agoMerge branch 'wip/otte/widgetfactory-dnd' into 'master'
Matthias Clasen [Tue, 27 Jul 2021 04:12:58 +0000 (04:12 +0000)]
Merge branch 'wip/otte/widgetfactory-dnd' into 'master'

Improve DND

See merge request GNOME/gtk!3785

4 years agowidget-factory: Add images that support dnd
Benjamin Otte [Mon, 26 Jul 2021 00:35:09 +0000 (02:35 +0200)]
widget-factory: Add images that support dnd

Just use the bottom left notebook for a GtkPicture with custom drag
source and drop target.

4 years agowidget-factory: Some new backgrounds
Matthias Clasen [Mon, 26 Jul 2021 14:48:42 +0000 (10:48 -0400)]
widget-factory: Some new backgrounds

Snowy wasn't ideal because of the aspect ratio.
Replace it by beach and nyc.

4 years agodroptarget: Make formats construct-only writable
Benjamin Otte [Mon, 26 Jul 2021 00:34:18 +0000 (02:34 +0200)]
droptarget: Make formats construct-only writable

This way, it can be set in GtkBuilder.

Also make sure to only ever look at the GTypes set in the formats, as
GtkDropTarget cannot deal with mime types.

4 years agobuilder: Add support for GdkContentFormats
Benjamin Otte [Mon, 26 Jul 2021 00:33:54 +0000 (02:33 +0200)]
builder: Add support for GdkContentFormats

4 years agotestsuite: Add contentformat tests
Benjamin Otte [Tue, 27 Jul 2021 01:25:15 +0000 (03:25 +0200)]
testsuite: Add contentformat tests

4 years agocontentformats: Add gdk_content_formats_parse()
Benjamin Otte [Mon, 26 Jul 2021 00:33:31 +0000 (02:33 +0200)]
contentformats: Add gdk_content_formats_parse()

4 years agoMerge branch 'matthiasc/for-master' into 'master'
Matthias Clasen [Mon, 26 Jul 2021 18:21:56 +0000 (18:21 +0000)]
Merge branch 'matthiasc/for-master' into 'master'

ngl: Cosmetics

See merge request GNOME/gtk!3786

4 years agongl: Cosmetics
Matthias Clasen [Mon, 26 Jul 2021 11:40:08 +0000 (07:40 -0400)]
ngl: Cosmetics

Use the macro we already have to check that colors
are fully transparent.

4 years agoMerge branch 'wip/compose-parser' into 'master'
Matthias Clasen [Mon, 26 Jul 2021 11:51:14 +0000 (11:51 +0000)]
Merge branch 'wip/compose-parser' into 'master'

Clean up the GtkComposeTable api

See merge request GNOME/gtk!3746

4 years agocontentformats: Change the format of gdk_content_formats_to_string()
Benjamin Otte [Mon, 26 Jul 2021 00:28:49 +0000 (02:28 +0200)]
contentformats: Change the format of gdk_content_formats_to_string()

Now, we just print a whitespace-separated list of GTypes and mime types.

This makes this neat for 2 things:

1. Parsing it (see next commit)
2. Using it in GtkBuilder (see commits after that)

In particular, the common case of supporting a single GType (or mime
type) looks like just printing the GType (or mime type), which in
GtkBuilder looks like
<property name="formats">GdkTexture</property>

4 years agodnd: Guard drags with a reference when finishing
Benjamin Otte [Mon, 26 Jul 2021 00:16:47 +0000 (02:16 +0200)]
dnd: Guard drags with a reference when finishing

Usually the "dnd-finished" signal will be used to unref the GdkDrag. In
those cases, we would lose the object, so that when we do the final
drag_drop_done() afterwards, we wouldn't have a remaining reference.

With the reference guard, this now works.

4 years ago4.3.2
Matthias Clasen [Fri, 23 Jul 2021 21:14:24 +0000 (17:14 -0400)]
4.3.2

4 years agoMerge branch 'misc-speedups' into 'master'
Matthias Clasen [Sun, 25 Jul 2021 02:03:46 +0000 (02:03 +0000)]
Merge branch 'misc-speedups' into 'master'

ngl: Speed up clipping calculations a bit

See merge request GNOME/gtk!3784

4 years agosizerequest: Simplify some code
Matthias Clasen [Sat, 24 Jul 2021 22:44:33 +0000 (18:44 -0400)]
sizerequest: Simplify some code

Avoid some repeated MAX().

4 years agosizerequest: Keep branches in sync
Matthias Clasen [Sat, 24 Jul 2021 22:41:09 +0000 (18:41 -0400)]
sizerequest: Keep branches in sync

There are some unintentional differences between
the path that uses a layout manager, and the path
that uses widget vfuncs. Sync them up.

4 years agowidget: Avoid some unnecessary back-and-forth casting
Matthias Clasen [Fri, 23 Jul 2021 14:18:44 +0000 (10:18 -0400)]
widget: Avoid some unnecessary back-and-forth casting

Avoid some unnecessary casting and a redundant early exit.

4 years agowidget: Avoid GObject data for action muxer
Matthias Clasen [Fri, 23 Jul 2021 00:59:01 +0000 (20:59 -0400)]
widget: Avoid GObject data for action muxer

Most widget have an action muxer now, so just
store it in GtkWidgetPrivate.

4 years agolayoutmanager: Avoid some overhead
Matthias Clasen [Fri, 23 Jul 2021 00:58:25 +0000 (20:58 -0400)]
layoutmanager: Avoid some overhead

Use inline getters for some things.

4 years agogridlayout: Avoid some unnecessary overhead
Matthias Clasen [Fri, 23 Jul 2021 00:53:49 +0000 (20:53 -0400)]
gridlayout: Avoid some unnecessary overhead

Use inline functions for some things.

4 years agogsk: Optimize gsk_transform_to...
Matthias Clasen [Sat, 24 Jul 2021 14:51:08 +0000 (10:51 -0400)]
gsk: Optimize gsk_transform_to...

Optimize these functions for the common cases.

4 years agogsk: Add a shortcut for a common transform case
Matthias Clasen [Sat, 24 Jul 2021 14:48:20 +0000 (10:48 -0400)]
gsk: Add a shortcut for a common transform case

Add a private getter for the translation part of a
transform node, to avoid pulling it out of the transform
over and over.

4 years agogsk: Add a private getter for container children
Matthias Clasen [Sat, 24 Jul 2021 13:49:09 +0000 (09:49 -0400)]
gsk: Add a private getter for container children

No need to get them one-by-one, in our inner loop.

4 years agongl: Reduce type checking overhead
Matthias Clasen [Sat, 24 Jul 2021 13:50:43 +0000 (09:50 -0400)]
ngl: Reduce type checking overhead

No need to be very careful here, these are entirely
internal types.

4 years agongl: Speed up clipping calculations a bit
Matthias Clasen [Fri, 23 Jul 2021 14:19:16 +0000 (10:19 -0400)]
ngl: Speed up clipping calculations a bit

Exit as early as possible from intersect_rounded_rectilinear.

4 years agoUpdate POTFILES.in
Piotr Drąg [Sat, 24 Jul 2021 12:38:51 +0000 (14:38 +0200)]
Update POTFILES.in

4 years agoMerge branch 'no-pposition' into 'master'
Emmanuele Bassi [Sat, 24 Jul 2021 11:45:00 +0000 (11:45 +0000)]
Merge branch 'no-pposition' into 'master'

gdk/x11: Do not set PPosition hint

See merge request GNOME/gtk!3781

4 years agogdk/x11: Do not set PPosition hint
Florian Müllner [Sat, 24 Jul 2021 04:32:16 +0000 (06:32 +0200)]
gdk/x11: Do not set PPosition hint

It is good practice for (floating) window managers to respect explicit
position hints from clients (as long as the window wouldn't end up
off-screen etc.).

Before commit 13d3afa56e9, GTK had a flag for setting the PPosition hint,
but now does so unconditionally. However the real intention is to *not*
request a fixed position, so don't do that.

4 years agoMerge branch 'wip/exalm/gtktext-selection-fix' into 'master'
Matthias Clasen [Fri, 23 Jul 2021 20:29:07 +0000 (20:29 +0000)]
Merge branch 'wip/exalm/gtktext-selection-fix' into 'master'

text: Use the widget y coordinate for gestures

See merge request GNOME/gtk!3780

4 years agotext: Use the widget y coordinate for gestures
Alexander Mikhaylenko [Fri, 23 Jul 2021 09:15:43 +0000 (14:15 +0500)]
text: Use the widget y coordinate for gestures

Currently we use layout coordinates and widget height when determining
where a click or drag has happened. If the widget has top padding (which it
does inside a GtkEntry, for example), the area where it's possible to select
text is shifted down, so the part of GtkText above the layout is not counted
as the draggable area and instead the equal area below the widget is counted.

Since GtkText is always single-line, there's no need to do any of that and
we can use widget coordinates. Then the draggable area matches the widget
and the problems goes away.

4 years agoMerge branch 'stack-page-name' into 'master'
Matthias Clasen [Fri, 23 Jul 2021 14:25:29 +0000 (14:25 +0000)]
Merge branch 'stack-page-name' into 'master'

stack: GtkStackPage:name is not construct-only

Closes #4109

See merge request GNOME/gtk!3778

4 years agoMerge branch 'matthiasc/for-master' into 'master'
Matthias Clasen [Thu, 22 Jul 2021 21:22:55 +0000 (21:22 +0000)]
Merge branch 'matthiasc/for-master' into 'master'

Cosmetics

See merge request GNOME/gtk!3779

4 years agoCosmetics
Matthias Clasen [Thu, 22 Jul 2021 21:02:21 +0000 (17:02 -0400)]
Cosmetics

Fix a comment typo.

4 years agostack: GtkStackPage:name is not construct-only
Matthias Clasen [Thu, 22 Jul 2021 20:55:15 +0000 (16:55 -0400)]
stack: GtkStackPage:name is not construct-only

We have a setter for this property, so we clearly
weren't serious when we marked it as construct-only.

Fixes: #4109
4 years agoMerge branch 'startup-profiling' into 'master'
Matthias Clasen [Thu, 22 Jul 2021 19:20:22 +0000 (19:20 +0000)]
Merge branch 'startup-profiling' into 'master'

Add more sysprof marks

See merge request GNOME/gtk!3777

4 years agoAdd more sysprof marks
Matthias Clasen [Thu, 22 Jul 2021 15:36:29 +0000 (11:36 -0400)]
Add more sysprof marks

Add a few more marks during gtk_init to figure out where
our startup time goes, and avoid the sysprof initialization
from distorting the first mark.

4 years agoMerge branch 'startup-profiling' into 'master'
Matthias Clasen [Thu, 22 Jul 2021 17:04:27 +0000 (17:04 +0000)]
Merge branch 'startup-profiling' into 'master'

Add more sysprof marks

See merge request GNOME/gtk!3776

4 years agoAdd more sysprof marks
Matthias Clasen [Thu, 22 Jul 2021 15:36:29 +0000 (11:36 -0400)]
Add more sysprof marks

Add a few more marks during gtk_init to figure out where
our startup time goes, and avoid the sysprof initialization
from distorting the first mark.

4 years agoMerge branch 'wip/otte/gleanup' into 'master'
Benjamin Otte [Thu, 22 Jul 2021 14:51:05 +0000 (14:51 +0000)]
Merge branch 'wip/otte/gleanup' into 'master'

reorganize GDK's GL code

See merge request GNOME/gtk!3726

4 years agoglx: Get rid fo DrawableInfo
Benjamin Otte [Thu, 22 Jul 2021 14:23:06 +0000 (16:23 +0200)]
glx: Get rid fo DrawableInfo

Store the frame counter in the surface, where it belongs.

4 years agogdkdisplay-win32.c: Don't call ReleaseDC() unnecessarily
Chun-wei Fan [Mon, 19 Jul 2021 09:13:53 +0000 (17:13 +0800)]
gdkdisplay-win32.c: Don't call ReleaseDC() unnecessarily

The dummy Win32 window that we use to capture display change events and
to create dummy WGL contexts was created with CS_OWNDC, so we really do
not need to (and should not) call ReleaseDC() on the HDC that we
obtained from it, so drop these calls.

4 years agoGDK-Win32: init_gl(): Default to WGL for now
Chun-wei Fan [Mon, 19 Jul 2021 02:48:03 +0000 (10:48 +0800)]
GDK-Win32: init_gl(): Default to WGL for now

Since the shaders need to be updated for using with GLES (libANGLE at
least), default to WGL for now.  Unfortunately it is not that common for
Windows to have GLES support, in which the easiest way to obtain such
support is via Google's libANGLE.

4 years agoGDK-Win32: Fixup, and cleanup WGL HDC handling
Chun-wei Fan [Mon, 19 Jul 2021 02:32:28 +0000 (10:32 +0800)]
GDK-Win32: Fixup, and cleanup WGL HDC handling

It turns out that the problem of the WGL window not drawing was due to
the fact that I messed up where I placed SwapBuffers() during the
conversion... doh:|

At the same time, stop storing the HDC in the GdkWin32GLContextWGL, but
instead always create it along the surface we created, so that it is ready
for use for operating with WGL when we are not dealing with "surfaceless"
contexts.  If we are dealing with "surfaceless" contexts, just use the
HDC of the dummy window that we created when we created the
Gdk(Win32)Display.

WGL contexts should now be in working order at this point.

4 years agoSplit out WGL/EGL stuff and simplify things
Chun-wei Fan [Wed, 14 Jul 2021 09:46:31 +0000 (17:46 +0800)]
Split out WGL/EGL stuff and simplify things

This commit attempts to split GdkWin32GLContext into two parts, one for
WGL and the other for EGL (ANGLE), and attempts to simplify things a
bit, by:

*  We are already creating a Win32 window to capture display changes,
   so we can just use that to act as our dummy window that we use to
   find out the pixel format that the system supports for WGL.  We also
   use it to obtain the dummy legacy WGL context that we will always
   require to create our more advanced Core WGL contexts.

*  Like what is done in X11, store up the WGL pixel format or the
   EGLConfig in our GdkWin32Display.

*  Ensure we do not create the dummy WGL context unnecessarily.

In this way, we can successfully create the WGL/EGL contexts, however
there are some issues at this point:

*  For WGL, the code successfully initializes and realizes the WGL
   Contexts, but for some reason things became invisible.  When running
   gtk4-demo, this can be verified by seeing the mouse cursor changing
   when moved to spots where one can resize the window, although they
   were invisible.

*  For EGL, the code initializes EGL but could not realize the EGL
   context as shaders failed to compile.  It seems like the shader issue
   is definitely outside the scope of this MR.

4 years agogl: Fix issue with EGL + nvidia
Benjamin Otte [Sat, 10 Jul 2021 00:29:17 +0000 (02:29 +0200)]
gl: Fix issue with EGL + nvidia

nvidia sets the default draw buffer to GL_NONE if EGL contexts are
initially bound to EGL_NO_SURFACE which is exactly what we are doing. So
bind them to GL_BACK when drawing, as they should be.

See https://phabricator.services.mozilla.com/D118743 for a discussion
about EGL_NO_CONTEXT and draw buffers.

4 years agoGDK: Add debug option for WGL usage
Chun-wei Fan [Wed, 14 Jul 2021 04:28:07 +0000 (12:28 +0800)]
GDK: Add debug option for WGL usage

This way, one can force using WGL on Windows even if EGL support was
enabled.  Also update the help text for gl-egl as it will apply for
Windows, albeit a bit later.

4 years agoGDK-Win32: Move some functions out of gdkglcontext-win32.c
Chun-wei Fan [Wed, 14 Jul 2021 04:19:52 +0000 (12:19 +0800)]
GDK-Win32: Move some functions out of gdkglcontext-win32.c

We want these to be out of the way as we split between WGL and EGL/ANGLE
GL contexts, so that they don't get in the way.

4 years agodisplay: Move GL selection code into gdkdisplay-x11.c
Benjamin Otte [Tue, 13 Jul 2021 03:23:41 +0000 (05:23 +0200)]
display: Move GL selection code into gdkdisplay-x11.c

This has the benefit that we can refactor it and make sure we deal with
GdkDisplay::init_gl() not being called at all because
GDK_DEBUG=gl-disable had been specified.

4 years agox11: Move code from GdkGLContextX11
Benjamin Otte [Tue, 13 Jul 2021 03:04:45 +0000 (05:04 +0200)]
x11: Move code from GdkGLContextX11

It's not used there, but both backends have independent
immplementationgs for it.

I want to get rid of GdkGLContextX11 and moving code from it is the
first step.

4 years agoinspector: Add support for displaying GL errors
Benjamin Otte [Fri, 9 Jul 2021 01:28:34 +0000 (03:28 +0200)]
inspector: Add support for displaying GL errors

Also, no need to show a GL version if GL isn't available.

4 years agogdk: Move GL context construction to GdkGLContext
Benjamin Otte [Fri, 9 Jul 2021 00:50:32 +0000 (02:50 +0200)]
gdk: Move GL context construction to GdkGLContext

Now that we have the display's context to hook into, we can use it to
construct other GL contexts and don't need a GdkSurface vfunc anymore.

This has the added benefit that backends can have different GdkGLContext
classes on the display and get new GLContexts generated from them, so
we get multiple GL backend support per GDK backend for free.

I originally wanted to make this a vfunc on GdkGLContextClass, but
it turns out all the abckends would just call g_object_new() anyway.

4 years agogl: Move vfunc
Benjamin Otte [Wed, 7 Jul 2021 02:40:34 +0000 (04:40 +0200)]
gl: Move vfunc

Instead of
  Display::make_gl_context_current()
we now have
  GLContext::clear_current()
  GLContext::make_current()

This fits better with the backends (we can actually implement
clearCurrent on macOS now) and makes it easier to implement different GL
backends for backends (like EGL/GLX on X11).

We also pass a surfaceless boolean to make_current() so the calling code
can decide if a surface needs to be bound or not, because the backends
were all doing whatever, which was very counterproductive.

4 years agogl: Require EGL_KHR_surfaceless_context with egl
Benjamin Otte [Wed, 7 Jul 2021 01:00:09 +0000 (03:00 +0200)]
gl: Require EGL_KHR_surfaceless_context with egl

The code to create and manage a fake egl surface to bind to is
complex and completely untested because everyone seems to support this
extension.

nvidia and Mesa do support it and according to Mesa devs, adding support
in a new driver is rather simple and Mesa drivers gain that feature
automatically, so all future drivers shoould have it.

4 years agogdk: Get rid of paint contexts
Benjamin Otte [Tue, 6 Jul 2021 02:50:01 +0000 (04:50 +0200)]
gdk: Get rid of paint contexts

... or more exactly: Only use paint contexts with
gdk_cairo_draw_from_gl().

Instead of paint contexts being the only contexts who call swapBuffer(),
any context can be used for this, when it's used with
begin_frame()/end_frame().

This removes 2 features:

1. We no longer need a big sharing hierarchy. All contexts are now
   shared with gdk_display_get_gl_context().
2. There is no longer a difference between attached and non-attached
   contexts. All contexts work the same way.

4 years agogl: Store the context::in-frame state in the current context
Benjamin Otte [Tue, 6 Jul 2021 02:47:15 +0000 (04:47 +0200)]
gl: Store the context::in-frame state in the current context

Do not treat the context as already current when the value
of context::in-frame changes.

This is so we can bind to EGL_NO_SURFACE if context::in-frame == false
and to context::surface if context::in-frame == true.

This allows getting rid of the attached property in future commits.

4 years agogl: Deprecate gdk_gl_context_get_shared_context()
Benjamin Otte [Sat, 10 Jul 2021 01:24:00 +0000 (03:24 +0200)]
gl: Deprecate gdk_gl_context_get_shared_context()

It's not used anymore. And in particular we do want to keep the display
context private, so we're not gonna return it from this function.

4 years agogdk: Add gdk_gl_context_is_shared()
Benjamin Otte [Wed, 30 Jun 2021 02:52:35 +0000 (04:52 +0200)]
gdk: Add gdk_gl_context_is_shared()

... and use it in the GL renderers.

4 years agongl: Store the shared driver in the display
Benjamin Otte [Mon, 5 Jul 2021 02:24:43 +0000 (04:24 +0200)]
ngl: Store the shared driver in the display

... instead of some random GL context.

4 years agogdk: Require EGL version 1.4 across the board
Benjamin Otte [Mon, 5 Jul 2021 01:04:08 +0000 (03:04 +0200)]
gdk: Require EGL version 1.4 across the board

Mesa currently ships 1.5.

4 years agogdk: Add GdkDisplay::init_gl vfunc
Benjamin Otte [Sun, 4 Jul 2021 23:57:03 +0000 (01:57 +0200)]
gdk: Add GdkDisplay::init_gl vfunc

The vfunc is called to initialize GL and it returns a "base" context
that GDK then uses as the context all others are shared with. So the GL
context share tree now looks like:

+ context from init_gl
  - context1
  - context2
  ...

So this is a flat tree now, the complexity is gone.

The only caveat is that backends now need to create a GL context when
initializing GL so some refactoring was needed.

Two new functions have been added:

* gdk_display_prepare_gl()
  This is public API and can be used to ensure that GL has been
  initialized or if not, retrieve an error to display (or debug-print).
* gdk_display_get_gl_context()
  This is a private function to retrieve the base context from
  init_gl(). It replaces gdk_surface_get_shared_data_context().

4 years agowayland: Don't pass GL config to get_egl_surface()
Benjamin Otte [Sun, 4 Jul 2021 18:55:53 +0000 (20:55 +0200)]
wayland: Don't pass GL config to get_egl_surface()

There's only one GL config.

4 years agowayland: Move fbconfig into the display
Benjamin Otte [Sun, 4 Jul 2021 17:48:11 +0000 (19:48 +0200)]
wayland: Move fbconfig into the display

Create it during init and then reuse it for all contexts.

While doing that, also improve error reporting - that's not used yet but
will in later commits.

4 years agogdk: Allow GdkDrawContext with a %NULL surface
Benjamin Otte [Sun, 4 Jul 2021 00:43:49 +0000 (02:43 +0200)]
gdk: Allow GdkDrawContext with a %NULL surface

This is not used yet, but it allows surfaceless GL contexts.

For that purpose, we need to make the display a construct-only property,
so that it can be set when the surface isn't.

This adds a bunch of very picky checks in the constructor so nothing bad
can happen.

4 years agogdk: Add a private struct to GdkDisplay
Benjamin Otte [Sat, 3 Jul 2021 23:43:16 +0000 (01:43 +0200)]
gdk: Add a private struct to GdkDisplay

... and move some members from the GdkDisplay struct.

We've always wanted to add one to isolate the display from the backends
a bit more, but so far it's never happened.

Now that I'm about to add more data to GdkDisplay, it's a good excuse to
start.

4 years agox11: Redo choice between EGL and GLX
Benjamin Otte [Fri, 2 Jul 2021 01:37:32 +0000 (03:37 +0200)]
x11: Redo choice between EGL and GLX

We try EGL first, but are very picky about what we accept.
If that fails, we try to go with GLX instead.
And if that also fails, we try EGL again, but this time accept anything.

The idea here is that EGL is the preferred method going forward, but GLX is
the tried and tested method that we know works. So if we detect issues with
EGL, we want to avoid using it in favor of GLX.

Also add a GDK_DEBUG=gl-egl option to force EGL at all costs and not try
GLX.

4 years agox11: Properly record the error when initializing GL
Benjamin Otte [Fri, 2 Jul 2021 01:21:14 +0000 (03:21 +0200)]
x11: Properly record the error when initializing GL

That way, we can give a useful error message when things break down for
users.

These error messages could still be improved in places (like looking at
the actual EGL error codes), but that seemed overkill.

4 years agox11: Do not call glXQueryExtension()
Benjamin Otte [Fri, 2 Jul 2021 00:33:18 +0000 (02:33 +0200)]
x11: Do not call glXQueryExtension()

epoxy does that already.

4 years agox11: Get Visual from EGL directly
Benjamin Otte [Fri, 18 Jun 2021 12:46:24 +0000 (14:46 +0200)]
x11: Get Visual from EGL directly

Query the EGL_VISUAL_ID from the egl Config and select a config with the
matching Visual.

This is currently broken on Mesa because it does not expose any RGBA
X Visuals in any EGL config, so we always end up with opaque Windows.

https://gitlab.freedesktop.org/mesa/mesa/-/issues/149

4 years agox11: Store the GLX drawable in the surface
Benjamin Otte [Tue, 29 Jun 2021 21:45:50 +0000 (23:45 +0200)]
x11: Store the GLX drawable in the surface

Also, stop using a dummy window for unattached GL contexts and instead
use the display's leader surface.

Again, this mirrors EGL.

4 years agox11: Use single GLX fbconfig and store it in the display
Benjamin Otte [Tue, 29 Jun 2021 20:10:48 +0000 (22:10 +0200)]
x11: Use single GLX fbconfig and store it in the display

This mirrors the code for the EGL config.

4 years agox11: Remove glx version check
Benjamin Otte [Tue, 29 Jun 2021 16:45:04 +0000 (18:45 +0200)]
x11: Remove glx version check

We only work with GLX >= 1.3 anyway, so don't explicitly check for it
and pretend to do something else that doesn't work otherwise.

4 years agox11: Remove unused struct member
Benjamin Otte [Tue, 29 Jun 2021 16:44:09 +0000 (18:44 +0200)]
x11: Remove unused struct member

We don't care if the GL context is direct at all.

4 years agoRevert "x11: Always fall back to GLX on NVIDIA"
Benjamin Otte [Tue, 15 Jun 2021 12:48:55 +0000 (14:48 +0200)]
Revert "x11: Always fall back to GLX on NVIDIA"

This reverts commit c35a6725b99722d91b0ed6580546c27c8f0849ba.

This approach doesn't work because if NVIDIA doesn't work for EGL, the
EGL implementation won't be provided by NVIDIA, so checking the vendor
doesn't work.

4 years agox11: Remove the dummy surface
Benjamin Otte [Sun, 13 Jun 2021 21:35:06 +0000 (23:35 +0200)]
x11: Remove the dummy surface

Instead, use the display's "leader surface" when no surface is required,
because we have it lying around.

Really, we want to use EGL_NO_SURFACE, but if that's not supported...

4 years agox11: Remove GdkVisual
Benjamin Otte [Sun, 13 Jun 2021 15:43:15 +0000 (17:43 +0200)]
x11: Remove GdkVisual

It's not used anymore.

4 years agox11: Rework Visual selection
Benjamin Otte [Sun, 13 Jun 2021 15:34:55 +0000 (17:34 +0200)]
x11: Rework Visual selection

Instead of going via GdkVisual, doing a preselection and letting the GL
initialization improve it, let the GL initialization pick an X Visual
directly using X Visual code directly.

The code should select the same visuals as before as it tries to apply
the same logic, but it's a rewrite, so I expect I messed something up.

4 years agoglx: Remove Visual cache
Benjamin Otte [Sat, 12 Jun 2021 09:13:22 +0000 (11:13 +0200)]
glx: Remove Visual cache

1. We're using EGL most of the time anyway, so if we wanted to cache
   things, we'd need to port it there.
2. Our GL handling is massively configurable, so determining when to use
   the cache and when not is a challenge.
3. It makes startup nondeterministic and depend on whether a GTK4 app
   has previously been started on this display and nobody thinks about
   that when debugging.
4. The only benefit of the caching is delaying GL initialization - which
   made sense in GTK3 where almost no app used GL but doesn't make sense
   in GTK4 where almost every app uses GL.

So unless I find a big benefit to reintroducing it, this cache will be
gone for good.